// Central hub for getting any user-facing text
// Handles translation (in the future), building texts from templates, capitalization etc

define(function () {
	var Text = {

		isDebugMode: false,
		language: null,

		irregularPlurals: {
			wildlife: "wildlife"
		},
		chineseText: {
			water: '水',
			rope: '绳索',
			metal: '金属',
			Camp: '营地',
			stamina: "耐力",
			resource_metal: "金属",
			resource_fuel: "燃料",
			resource_rubber: "橡胶",
			resource_rope: "绳索",
			resource_food: "食物",
			resource_water: "水",
			resource_concrete: "混凝土",
			resource_herbs: "药材",
			resource_medicine: "药品",
			resource_tools: "工具",
			resource_robots: "机器人",
			item_exploration_1: "撬锁刀",
			rumours: "传闻",
			evidence: "线索",
			insight: "洞察力",
			"Trap": "陷阱",
			collector_water: "Bucket",
			beacon: "Beacon",
			"[Staircase Up]": "上行电梯",
			"[Staircase Down]": "下行电梯",
			passageUpElevator: "Elevator Up (Repair)",
			passageUpHole: "Elevator Up (Build)",
			passageDownStairs: "",
			passageDownElevator: "Elevator Down (Repair)",
			passageDownHole: "Elevator Down (Build)",
			spaceship1: "Colony Hull",
			spaceship2: "Colony Shield",
			spaceship3: "Colony Life Support",
			greenhouse: "Greenhouse",
			tradepost_connector: "Great Elevator",
			sundome: "Sun Dome",
			luxuryOutpost: "Resource outpost",

			home: "Tent",
			house: "Hut",
			house2: "Tower block",
			storage: "Storage",
			campfire: "Campfire",
			darkfarm: "Snail farm",
			hospital: "Clinic",
			generator: "Generator",
			tradepost: "Trading post",
			inn: "Inn",
			apothecary: "Apothecary",
			smithy: "Smithy",
			cementmill: "Cement mill",
			robotFactory: "Robot factory",
			library: "Library",
			shrine: "Shrine",
			temple: "Temple",
			market: "Market",
			radiotower: "Radio tower",
			barracks: "Barracks",
			fortification: "Fortification",
			stable: "Caravan Stable",
			aqueduct: "Aqueduct",
			researchcenter: "Research center",
			lights: "Lights",
			square: "Square",
			garden: "Moss garden",
			"max vision": "最大视野",
			"attack": "攻击",
			"defence": "防御",
			"shield": "盾",
			"attack speed": "攻击速度",
			"movement cost": "移动成本",
			"scavenge cost": "清理成本",
			"scavenge bonus": "拾荒者奖励",
			"scouting cost": "侦察费",
			"bag size": "背包大小",
			"warmth": "温暖",
			"radiation prot": "辐射防护",
			"radiation protection": "辐射防护",
			"poison prot": "毒物保护",
			"poison protection": "毒物保护",
			"sun prot": "防晒",
			"sunblindness protection": "防晒",
			"hazards": "危险",
			"surveying (hazards)": "测量（危险）",
			"supplies": "供应",
			"surveying (supplies)": "测量（供应）",
			"ingredients": "成分",
			"surveying (ingredients)": "调查（成分）",
		},
		getText: function (key) {
			return isDebugMode ? key + "|" : key;
		},

		capitalize: function (string) {
			for (let i = 0; i < string.length; i++) {
				var c = string.charAt(i);
				if (c == "[" || c == "]" || c == "(" || c == ")") continue;
				return string.substr(0, i) + c.toUpperCase() + string.substr(i + 1);
			}
			return string;
		},

		getArticle: function (s) {
			return this.language.getIndefiniteArticle(s);
		},

		isPlural: function (s) {
			if (s[s.length - 1] === "s") {
				if (s[s.length - 1] === "e") return true;
				// can't tell
				return null;
			}
			return false;
		},

		pluralify: function (s) {
			let irregular = this.getIrregularPlural(s);
			if (irregular) return irregular;

			if (s.endsWith("roach")) {
				return s + "（多个）";
			} else if (s[s.length - 1] !== "s") {
				return s + "（多个）";
			} else {
				return s;
			}
		},

		depluralify: function (s) {
			if (s[s.length - 1] === "s") {
				return s.substr(0, s.length - 1);
			}

			return s;
		},

		addArticle: function (s) {
			if (this.isPlural(s)) return s;
			return this.getArticle(s) + " " + s;
		},

		getIrregularPlural: function (s) {
			let parts = s.split(" ");
			let w = parts[parts.length - 1];
			if (Object.keys(this.irregularPlurals).indexOf(w) >= 0) {
				parts[parts.length - 1] = this.irregularPlurals[w];
				return parts.join(" ");
			}
			return null;
		},
		getCustomizeChinese(key) {
			if (this.chineseText[key]) return this.chineseText[key]
			return key
		},

	};
	return Text;
});
